#!/bin/bash

# 设置变量
NDK_ROOT="/mnt/android_home/ndk/android-ndk-r28c"  # 修改为你的 NDK 路径
TOOLCHAIN="$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64"
export PKG_CONFIG_PATH="/opt/module/output/android/x86-64/21/lib/pkgconfig"
API=21
TARGET="x86_64-linux-android"
CC="$TOOLCHAIN/bin/x86_64-linux-android$API-clang"
CXX="$TOOLCHAIN/bin/x86_64-linux-android$API-clang++"
STRIP="$TOOLCHAIN/bin/x86_64-linux-android-strip"
PREFIX="/opt/android/x86_64"
#cd /opt/module/src/ffmpeg/n8.1-dev
# 清理旧文件
# make clean
rm -rf *
# 配置
/opt/module/src/ffmpeg/n8.0/configure \
  --disable-doc \
  --disable-programs \
  --disable-ffmpeg \
  --disable-ffplay \
  --disable-ffprobe \
  --disable-symver \
  --disable-everything \
  --disable-doc \
  --disable-x86asm \
  --disable-asm \
  --enable-debug \
  --enable-hardcoded-tables \
  --enable-optimizations \
  --enable-pthreads \
  --enable-neon \
  --enable-nonfree \
  --enable-asm \
  --enable-inline-asm \
  --enable-decoders \
  --enable-encoders \
  --enable-demuxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-muxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-parser=h264,h265,aac,mpeg4video,mpegvideo \
  --enable-protocol=file,http,https,rtmp,rtsp,rtp \
  --enable-filter=scale,resample,crop,pad,format,aformat \
  --optflags='-O2 -fno-math-errno -fno-signed-zeros -fno-trapping-math' \
  --extra-cflags='-g1 -fPIC -fdata-sections -ffunction-sections -march=x86-64' \
  --extra-ldflags='-s -Wl,--gc-sections' \
  --enable-gpl \
  --enable-small \
  --enable-version3 \
  --disable-shared \
  --enable-static \
  --pkg-config=pkg-config \
  --enable-cross-compile \
  --prefix=$PREFIX \
  --target-os=android \
  --arch=x86_64 \
  --cpu=x86-64 \
  --cc=$CC \
  --cxx=$CXX \
  --strip=$STRIP \
  --enable-libspeex
# 检查配置是否成功
if [ $? -ne 0 ]; then
  echo "❌ 配置失败"
  exit 1
fi

# 编译
#make -j$(nproc)
#make install

echo "✅ FFmpeg for x86_64 编译完成，输出目录：$PREFIX"